package com.znsb.msfq.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.znsb.msfq.R;
import com.znsb.msfq.bean.MessageBean;
import com.znsb.msfq.utils.GetIsparityTime;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;


/**
 * @name：
 * @author： 孙科技
 * @phone： 13308334117
 * @createTime： 2017/2/10
 * @modifyTime： 2017/2/10
 * @explain：
 */

public class MyMessageRVAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private List<MessageBean.DataListBean> dataList;
    private Context context;

    public MyMessageRVAdapter(Context context, List<MessageBean.DataListBean> dataList) {
        this.context = context;
        this.dataList = dataList;
    }

    public void updateList(List<MessageBean.DataListBean> dataList) {
        this.dataList = dataList;
        notifyDataSetChanged();
    }

    @Override
    public int getItemCount() {
        return dataList.size();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View layout = LayoutInflater.from(context).inflate(R.layout.item_message_view, parent, false);
        return new MyHolder(layout);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof MyHolder) {
            ((MyHolder) holder).msgCenterItemTv.setText(dataList.get(position).getTitle() + "");

            ((MyHolder) holder).msgCenterItemDate.setText(GetIsparityTime.InputTimetampAll(dataList.get(position).getCreateTime() + ""));
            ((MyHolder) holder).msgCenterItemContent.setText(dataList.get(position).getMessage() + "");
            if (dataList.get(position).getIsRead() == 0)
                ((MyHolder) holder).msgCenterItemBit.setVisibility(View.VISIBLE);
            else
                ((MyHolder) holder).msgCenterItemBit.setVisibility(View.GONE);
        }
    }

    class MyHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.msg_center_item_bit)
        ImageView msgCenterItemBit;
        @Bind(R.id.msg_center_item_img)
        ImageView msgCenterItemImg;
        @Bind(R.id.msg_center_item_tv)
        TextView msgCenterItemTv;
        @Bind(R.id.msg_center_item_date)
        TextView msgCenterItemDate;
        @Bind(R.id.msg_center_item_content)
        TextView msgCenterItemContent;

        public MyHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
